package cn.stylefeng.guns.modular.project.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.comm.bean.BetweenMonth;
import cn.stylefeng.guns.comm.util.BetweenTimeUtil;
import cn.stylefeng.guns.modular.project.entity.Project;
import cn.stylefeng.guns.modular.project.mapper.ProjectMemberMapper;
import cn.stylefeng.guns.modular.project.mapper.ProjectMemberWorkMapper;
import cn.stylefeng.guns.modular.project.model.params.ProjectMemberParam;
import cn.stylefeng.guns.modular.project.model.params.ProjectMemberWorkParam;
import cn.stylefeng.guns.modular.project.model.params.ProjectParam;
import cn.stylefeng.guns.modular.project.model.result.ProjectMemberResult;
import cn.stylefeng.guns.modular.project.model.result.ProjectMemberWorkResult;
import cn.stylefeng.guns.modular.project.service.ProjectService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 项目信息控制器
 *
 * @author
 * @Date 2019-10-15 13:38:52
 */
@Controller
@RequestMapping("/project")
public class ProjectController extends BaseController {

    private String PREFIX = "/project";

    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProjectMemberWorkMapper projectMemberWorkMapper;
    @Autowired
    private ProjectMemberMapper projectMemberMapper;

    /**
     * 跳转到主页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/project.html";
    }

    /**
     * 新增页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/project_add.html";
    }

    /**
     * 编辑页面
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/project_edit.html";
    }

    /**
     * 新增接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProjectParam projectParam) {
        this.projectService.add(projectParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProjectParam projectParam) {
        this.projectService.update(projectParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProjectParam projectParam) {
        this.projectService.delete(projectParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author
     * @Date 2019-10-15
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProjectParam projectParam) {
        Project detail = this.projectService.getById(projectParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author
     * @Date 2019-10-15
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProjectParam projectParam) {
        return this.projectService.findPageBySpec(projectParam);
    }

    @RequestMapping("/workhour")
    @ResponseBody
    public ResponseData projectWorkHour(ProjectParam projectParam) {
        ProjectMemberWorkParam paramCondition = new ProjectMemberWorkParam();
        paramCondition.setProjectId(projectParam.getId());
        List<ProjectMemberWorkResult> workHourByProject = projectMemberWorkMapper.findWorkHourByProject(paramCondition);
        return ResponseData.success(workHourByProject);
    }

    @RequestMapping("/workhour/yyyymm")
    @ResponseBody
    public ResponseData workHourGroupByYYYYmm(ProjectParam projectParam) {
        ProjectMemberParam paramCondition = new ProjectMemberParam();
        paramCondition.setProjectId(projectParam.getId());
        List<ProjectMemberResult> workHourByProject = projectMemberMapper.groupByYYYYmm(paramCondition);
        return ResponseData.success(workHourByProject);
    }

    @RequestMapping("/workhourstatic")
    public String workhourstatic(int projectId) {
        setAttr("projectId", projectId);
        return PREFIX + "/project_detail.html";
    }
}


